//
//  AIWalletListViewCell.m
//  Mia
//
//  Created by Vill on 2024/1/13.
//

#import "AIWalletListViewCell.h"

@interface AIWalletListViewCell ()

// 背景
@property (weak, nonatomic) IBOutlet UIView *bgContain;
// 钻石背景
@property (weak, nonatomic) IBOutlet UIImageView *diamindImg;
// 折扣背景
@property (weak, nonatomic) IBOutlet UIImageView *offsetImg;
// 折扣数量
@property (weak, nonatomic) IBOutlet UILabel *offsetLbl;
// 新用户背景
@property (weak, nonatomic) IBOutlet UIImageView *nUserImg;
// 新用户文本
@property (weak, nonatomic) IBOutlet UILabel *nUserLbl;
// 价格
@property (weak, nonatomic) IBOutlet UIButton *priceBtn;
// 钻石数
@property (weak, nonatomic) IBOutlet UILabel *coinsLbl;
// 赠送金币
@property (weak, nonatomic) IBOutlet UILabel *goldsLbl;
// 钻石数Y值
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *coinsYCons;

@end

@implementation AIWalletListViewCell

+(instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *ID = @"AIWalletListViewCell";
    AIWalletListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil){
       cell = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil].lastObject;
    }
    return cell;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.bgContain.backgroundColor = [UIColor colorHex:@"#FFFFFF" alpha:0.2];
    self.bgContain.layer.cornerRadius = PTW(15);
    self.bgContain.layer.masksToBounds = YES;
    
    self.offsetImg.hidden = YES;
    self.offsetLbl.hidden = YES;
    self.offsetLbl.numberOfLines = 0;
    self.offsetLbl.font = [UIFont fontWithWeight:MTBold size:PTW(10)];

    self.nUserImg.hidden = YES;
    self.nUserLbl.hidden = YES;
    self.nUserLbl.text = @"New User";
    
    self.priceBtn.titleLabel.font = [UIFont fontWithWeight:MTBold size:PTW(12)];
    self.priceBtn.backgroundColor = [UIColor colorHex:@"#EFEFEF"];
    self.priceBtn.layer.cornerRadius = PTW(35)/2;
    self.priceBtn.layer.shadowColor = [UIColor colorHex:@"#FFFFFF" alpha:0.68].CGColor;
    self.priceBtn.layer.shadowOffset = CGSizeMake(0,0);
    self.priceBtn.layer.shadowOpacity = 1;
    self.priceBtn.layer.shadowRadius = 8.5;
    self.priceBtn.userInteractionEnabled = NO;
    
    self.coinsLbl.font = [UIFont fontWithWeight:MTBold size:PTW(20)];
    self.goldsLbl.font = [UIFont fontWithWeight:MTBold size:PTW(12)];
    self.goldsLbl.hidden = YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setWalletModel:(AIWalletModel *)walletModel{
    _walletModel = walletModel;
    
    // 钻石数
    NSString *diaImg = [NSString stringWithFormat:@"ai_wallet_%@",walletModel.price];
    self.diamindImg.image = KImaged(diaImg);
    
    // 新用户
    self.nUserImg.hidden = !walletModel.newUser;
    self.nUserLbl.hidden = !walletModel.newUser;
    
    // 价格
    [self.priceBtn setTitle:[NSString stringWithFormat:@"$%@",walletModel.price] forState:UIControlStateNormal];
    // 金币数
    self.coinsLbl.text = [NSString stringWithFormat:@"%ld",walletModel.amount];
    
    if(walletModel.extraAmonut > 0){
        self.coinsYCons.constant = -PTW(4);
        self.goldsLbl.text = [NSString stringWithFormat:@"Gift %ld cions",walletModel.extraAmonut];
        self.goldsLbl.hidden = NO;
        self.offsetImg.hidden = NO;
        self.offsetLbl.hidden = NO;
        self.offsetLbl.text = [NSString stringWithFormat:@"%.f%%\nOFF",(float)walletModel.extraAmonut*100/(float)(walletModel.extraAmonut+walletModel.amount)];
    }
}


@end
